package only.level5.railgun.ysartifactsimulation.utils;

import only.level5.railgun.ysartifactsimulation.Bean.CharacterScene;
import only.level5.railgun.ysartifactsimulation.suit.ArtifactSuitEffect;
import only.level5.railgun.ysartifactsimulation.suit.CrimsonWitch;
import only.level5.railgun.ysartifactsimulation.weapon.Homa;
import only.level5.railgun.ysartifactsimulation.weapon.Weapon;

import java.util.List;

public class Hutao {

    public static CharacterScene getCharterFinalProperties(List<double[]> artifactInfos) {
        CharacterScene hutao = initHutao();
        Weapon homa = new Homa(1);
        int cwNum = 0;
        double[] artifactFinal = null;
        for (double[] artifactInfo : artifactInfos) {
            int suitCode = (int) artifactInfo[20];
            if (suitCode == 0) {
                cwNum++;
            }
            artifactFinal = CalcUtils.addArtifacts(artifactFinal, artifactInfo);
        }
        assert artifactFinal != null;
        CharacterScene characterScene = finalScene(hutao, homa, artifactFinal);

        ArtifactSuitEffect crimsonWitch = new CrimsonWitch(1);
        if (cwNum >= 2) {
            crimsonWitch.setEffect2Piece(characterScene);
        }
        if (cwNum >= 4) {
            crimsonWitch.setEffect4Piece(characterScene);
        }
        characterScene.setSceneArts(artifactInfos);
        return characterScene;
    }


    public static CharacterScene initHutao() {
        CharacterScene hutao = new CharacterScene();
        hutao.setAtk(106d);
        hutao.setHp(15552d);
        hutao.setCritDmg(0.884);
        hutao.setCritRate(0.05);
        hutao.setLevel(90);
        hutao.setSkillDmg(2.426);
        hutao.setIncrease(0.33);
        hutao.setReaction(1.5);
        return hutao;
    }

    public static void specialAbility(CharacterScene base) {
        double totalHp = base.getHp() + base.getHp_ex();
        base.setAtk_ex(base.getAtk_ex() + totalHp * 0.0626);
    }

    public static CharacterScene finalScene(CharacterScene base, Weapon weapon, double[] artifactTotal) {
        weapon.mainStatEnhance(base);
        weapon.subStatEnhance(base);
        if (artifactTotal[1] != 0) {
            base.setAtk_ex(base.getAtk_ex() + artifactTotal[1]);
        }
        if (artifactTotal[4] != 0) {
            base.addAtk(artifactTotal[4]);
        }
        if (artifactTotal[2] != 0) {
            base.addHp(artifactTotal[2]);
        }
        if (artifactTotal[5] != 0) {
            base.addHp(base.getHp() * artifactTotal[5]);
        }
        if (artifactTotal[7] != 0) {
            base.setMastery(base.getMastery() + (int) artifactTotal[7]);
        }
        if (artifactTotal[9] != 0) {
            base.addCritRate(artifactTotal[9]);
        }
        if (artifactTotal[10] != 0) {
            base.addCritDmg(artifactTotal[10]);
        }
        if (artifactTotal[14] != 0) {
            base.addIncrease(artifactTotal[14]);
        }
        weapon.specialAbility(base);
        Hutao.specialAbility(base);

        return base;
    }

    public static void calcArtifactScore(double[] artifact) {
        double score = artifact[9] * 10 + artifact[10] * 5 + artifact[14] * 3 + artifact[5] * 1.5 + artifact[7] / 300 + artifact[4] ;
        score = score * 1000;
        if (artifact[20] == 0) {
            score += 150 * 1.5 * 3;
        }
        if (artifact[0] < 2){
            score += 800;
        }
        artifact[22] = score;
    }
}
